package com.woniuxy;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

/**
 * @Author 罗蔚
 * @Date 2022/4/13 14:32
 * @Description TODO
 */
public class ParseJWT {
    public static void main(String[] args) {
        String token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxMjMwNiIsInN1YiI6ImFkbWluIiwiaWF0IjoxNjQ5ODMxNzY0LCJteU5hbWUiOiLnvZfolJoiLCJteUNvdW50cnkiOiJDaGluYSJ9.8x7OOj2EWtETXBl9b8x3YDBpTJu3QII7O1OFJsWw0u0";
        //通过签名生成
        Claims claims = Jwts.parser().setSigningKey("woniu")
                .parseClaimsJws(token).getBody();
        System.out.println(claims.getId());
        System.out.println("主体是哪个用户："+claims.getSubject());
        System.out.println("签名(生成token)的时间："+claims.getIssuedAt());
        System.out.println(claims.get("myName"));
        System.out.println(claims.get("myCountry"));
    }
}
